var api = require('../../utils/api.js');
var app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    showlogs:0,
    logs: [],
    info: [],
    array: ['不含税','税率1%', '税率3%', '税率6%'],
    setmoney: 0,
    savemoney: 0,
    savemoneyb: 0,
    bili: 0,
    columns: [{
        name: '姓名',
        width: 100
      },
      {
        name: '年龄',
        width: 80
      },
    ],
    rows: [{
        data: ['张三', 25, '工程师', '北京']
      },
      {
        data: ['李四', 30, '设计师', '上海']
      },
      {
        data: ['王五', 28, '教师', '广州']
      },
      {
        data: ['赵六', 35, '医生', '深圳']
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    that.setData({
      id: options.id
    })

  },

  onShow() {
    this.getclearingdetail();
  },

  getclearingdetail() {
    var id = this.data.id;
    var that = this;
    api.post({
      url: 'cases/getclearingbyid',
      data: {
        id: id
      },
      success: data => {
        console.log(data)
        that.setData({
          info: data.data
        })
      }
    })

    api.post({
      url: 'cases/getclearingdetail',
      data: {
        id: id
      },
      success: data => {
        console.log(data)
        that.setData({
          lists: data.data
        })
      }
    })
  },

  savemoney(ret) {
    console.log(ret);
    var id = ret.currentTarget.dataset.id;
    var that = this;
    var savemoney = ret.currentTarget.dataset.money;

    that.setData({
      setmoney: 1,
      savemoney: savemoney,
      logid: id
    })




  },

  hidewind() {
    this.setData({
      setmoney: 0
    })
  },
  getsavemoneyb(ret) {

    console.log(ret);
    var savemoneyb = ret.detail.value;
    var savemoney = this.data.savemoney;

    var bili = (1 - (savemoneyb / savemoney)) * 100;
    bili = parseFloat(bili.toFixed(2));

    this.setData({
      savemoneyb: savemoneyb,
      bili: bili
    })


  },
  addmoneybyid() {

    var that = this;
    var id = this.data.logid;
    var money = this.data.savemoneyb;

    api.post({
      url: 'cases/setclearingmoneybyid',
      data: {
        id: id,
        money: money
      },
      success: data => {

        wx.showToast({
          title: data.msg,
          icon: 'none'
        })

        that.setData({
          setmoney: 0,
          bili: 0
        })

        that.getclearingdetail();
      }
    })

  },

  setsuilv(ret) {
    console.log(ret);
    var i = ret.detail.value;
    var array = this.data.array;

    var taxrate = array[i];

    console.log(taxrate)
    var that = this;
    var id = this.data.id;

    api.post({
      url: 'cases/setsuilvbyid',
      data: {
        id: id,
        taxrate: taxrate
      },
      success: data => {

        that.getclearingdetail();
      }
    })


  },

  seelogs() {

    var that = this;
    var id = this.data.id;

    api.post({
      url: 'cases/getclearinglogbyid',
      data: {
        id: id
      },
      success: data => {

        that.setData({
          logs: data.data,
          showlogs:1
        });
      }

    })
  },
  //
  hidelogs(){

      this.setData({
        showlogs:0
      })
  }




})